<!DOCTYPE html>
<html><head>
    <meta charset="UTF-8">
    <meta http-equiv="x-UA-Compatible" content="ie=Edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Crafty - Crafty Core</title>
    <link type="text/css" rel="stylesheet" href="../craftyjs-site.css">
    <link rel="shortcut icon" href="../favicon.ico">

</head>
<body>
<div id="header-background"></div>
<div id="page-frame">
    <div id="header">
        <nav class="navbar">
            <div class="container-fluid">
                <div class="navbar-header">
                    <a class="navbar-brand" href="../"> <img class="logo" src="../images/text-logo.png"> </a>

                </div>
                <div class="collapse navbar-collapse navbar-right" id="bs-example-navbar-collapse-1">
                    <ul class="nav navbar-nav">
                        <li><a href="../">首页</a></li>
                        <li><a href="../getting-started/">快速开始</a></li>
                        <li><a href="../documentation/">文档</a></li>
                        <li><a href="../api/">API</a></li>
                        <li><a href="../components/">组件</a></li>
                        <li class="emph"><a href="../#install">下载</a></li>
                    </ul>
                </div>
            </div>
        </nav>
    </div>


    <div id="main">
        <div id="content" class="container">


            <div id="docs">
                <div class="toc-holder" id="doc-nav">
                    <ul id="doc-level-one">
                        <li><a href="events.html">事件列表</a></li>
                        <li class="category">核心
                            <ul class="category-list">
                                <li><a href="Crafty.html">Crafty</a></li>
                                <li><a href="Crafty Core.html">Crafty Core</a></li>
                                <li><a href="Crafty-bind.html">Crafty.bind()</a></li>
                                <li><a href="Crafty-c.html">Crafty.c()</a></li>
                                <li><a href="Crafty-clone.html">Crafty.clone()</a></li>
                                <li><a href="Crafty-defineField.html">Crafty.defineField()</a></li>
                                <li><a href="Crafty-e.html">Crafty.e()</a></li>
                                <li><a href="Crafty-extend.html">Crafty.extend()</a></li>
                                <li><a href="Crafty-frame.html">Crafty.frame()</a></li>
                                <li><a href="Crafty-getVersion.html">Crafty.getVersion()</a></li>
                                <li><a href="Crafty-init.html">Crafty.init()</a></li>
                                <li><a href="Crafty-isPaused.html">Crafty.isPaused()</a></li>
                                <li><a href="Crafty-one.html">Crafty.one()</a></li>
                                <li><a href="Crafty-pause.html">Crafty.pause()</a></li>
                                <li><a href="Crafty-s.html">Crafty.s()</a></li>
                                <li><a href="Crafty-settings.html">Crafty.settings</a></li>
                                <li><a href="Crafty-stage.html">Crafty.stage</a></li>
                                <li><a href="Crafty-stop.html">Crafty.stop()</a></li>
                                <li><a href="Crafty-support.html">Crafty.support</a></li>
                                <li><a href="Crafty-trigger.html">Crafty.trigger()</a></li>
                                <li><a href="Crafty-unbind.html">Crafty.unbind()</a></li>
                                <li><a href="Crafty-uniqueBind.html">Crafty.uniqueBind()</a></li>
                            </ul>
                        </li>
                        <li class="category">2D
                            <ul class="category-list">
                                <li><a href="2D.html">2D</a></li>
                                <li><a href="AngularMotion.html">AngularMotion</a></li>
                                <li><a href="Collision.html">Collision</a></li>
                                <li><a href="Crafty-circle.html">Crafty.circle</a></li>
                                <li><a href="Crafty-diamondIso.html">Crafty.diamondIso</a></li>
                                <li><a href="Crafty-HashMap.html">Crafty.HashMap</a></li>
                                <li><a href="Crafty-isometric.html">Crafty.isometric</a></li>
                                <li><a href="Crafty-map.html">Crafty.map</a></li>
                                <li><a href="Crafty-math-Matrix2D.html">Crafty.math.Matrix2D</a></li>
                                <li><a href="Crafty-math-Vector2D.html">Crafty.math.Vector2D</a></li>
                                <li><a href="Crafty-polygon.html">Crafty.polygon</a></li>
                                <li><a href="Crafty-raycast.html">Crafty.raycast()</a></li>
                                <li><a href="Crafty-rectManager.html">Crafty.rectManager</a></li>
                                <li><a href="Gravity.html">Gravity</a></li>
                                <li><a href="GroundAttacher.html">GroundAttacher</a></li>
                                <li><a href="Motion.html">Motion</a></li>
                                <li><a href="Supportable.html">Supportable</a></li>
                            </ul>
                        </li>
                        <li class="category">动画
                            <ul class="category-list">
                                <li><a href="Crafty-easing.html">Crafty.easing</a></li>
                                <li><a href="SpriteAnimation.html">SpriteAnimation</a></li>
                                <li><a href="Tween.html">Tween</a></li>
                            </ul>
                        </li>
                        <li class="category">资源
                            <ul class="category-list">
                                <li><a href="Crafty-asset.html">Crafty.asset()</a></li>
                                <li><a href="Crafty-assets.html">Crafty.assets</a></li>
                                <li><a href="Crafty-imageWhitelist.html">Crafty.imageWhitelist()</a></li>
                                <li><a href="Crafty-load.html">Crafty.load()</a></li>
                                <li><a href="Crafty-paths.html">Crafty.paths()</a></li>
                                <li><a href="Crafty-removeAssets.html">Crafty.removeAssets()</a></li>
                            </ul>
                        </li>
                        <li class="category">音频
                            <ul class="category-list">
                                <li><a href="Crafty-audio.html">Crafty.audio</a></li>
                            </ul>
                        </li>
                        <li class="category">控制
                            <ul class="category-list">
                                <li><a href="Controllable.html">Controllable</a></li>
                                <li><a href="Controls.html">Controls</a></li>
                                <li><a href="Draggable.html">Draggable</a></li>
                                <li><a href="Fourway.html">Fourway</a></li>
                                <li><a href="Jumper.html">Jumper</a></li>
                                <li><a href="Multiway.html">Multiway</a></li>
                                <li><a href="Twoway.html">Twoway</a></li>
                            </ul>
                        </li>
                        <li class="category">调试
                            <ul class="category-list">
                                <li><a href="Crafty-error.html">Crafty.error()</a></li>
                                <li><a href="Crafty-log.html">Crafty.log()</a></li>
                                <li><a href="DebugCanvas.html">DebugCanvas</a></li>
                                <li><a href="DebugPolygon.html">DebugPolygon</a></li>
                                <li><a href="DebugRectangle.html">DebugRectangle</a></li>
                                <li><a href="SolidAreaMap.html">SolidAreaMap</a></li>
                                <li><a href="SolidHitBox.html">SolidHitBox</a></li>
                                <li><a href="VisibleMBR.html">VisibleMBR</a></li>
                                <li><a href="WiredAreaMap.html">WiredAreaMap</a></li>
                                <li><a href="WiredHitBox.html">WiredHitBox</a></li>
                            </ul>
                        </li>
                        <li class="category">事件
                            <ul class="category-list">
                                <li><a href="Crafty-addEvent.html">Crafty.addEvent()</a></li>
                                <li><a href="Crafty-bind.html">Crafty.bind()</a></li>
                                <li><a href="Crafty-one.html">Crafty.one()</a></li>
                                <li><a href="Crafty-removeEvent.html">Crafty.removeEvent()</a></li>
                                <li><a href="Crafty-trigger.html">Crafty.trigger()</a></li>
                                <li><a href="Crafty-unbind.html">Crafty.unbind()</a></li>
                                <li><a href="Crafty-uniqueBind.html">Crafty.uniqueBind()</a></li>
                            </ul>
                        </li>
                        <li class="category">游戏循环
                            <ul class="category-list">
                                <li><a href="Crafty-timer.html">Crafty.timer</a></li>
                            </ul>
                        </li>
                        <li class="category">图形
                            <ul class="category-list">
                                <li><a href="Canvas.html">Canvas</a></li>
                                <li><a href="CanvasLayer.html">CanvasLayer</a></li>
                                <li><a href="Color.html">Color</a></li>
                                <li><a href="Crafty-assignColor.html">Crafty.assignColor()</a></li>
                                <li><a href="Crafty-background.html">Crafty.background()</a></li>
                                <li><a href="Crafty-createLayer.html">Crafty.createLayer()</a></li>
                                <li><a href="Crafty-defaultShader.html">Crafty.defaultShader()</a></li>
                                <li><a href="Crafty-domHelper.html">Crafty.domHelper</a></li>
                                <li><a href="Crafty-pixelart.html">Crafty.pixelart()</a></li>
                                <li><a href="Crafty-sprite.html">Crafty.sprite()</a></li>
                                <li><a href="Crafty-WebGLShader.html">Crafty.WebGLShader()</a></li>
                                <li><a href="DOM.html">DOM</a></li>
                                <li><a href="DomLayer.html">DomLayer</a></li>
                                <li><a href="HTML.html">HTML</a></li>
                                <li><a href="Image.html">Image</a></li>
                                <li><a href="Particles.html">Particles</a></li>
                                <li><a href="Renderable.html">Renderable</a></li>
                                <li><a href="Sprite.html">Sprite</a></li>
                                <li><a href="Text.html">Text</a></li>
                                <li><a href="WebGL.html">WebGL</a></li>
                                <li><a href="WebGLLayer.html">WebGLLayer</a></li>
                            </ul>
                        </li>
                        <li class="category">输入
                            <ul class="category-list">
                                <li><a href="AreaMap.html">AreaMap</a></li>
                                <li><a href="Button.html">Button</a></li>
                                <li><a href="Crafty-findPointerEventTargetByComponent.html">Crafty.findPointerEventTargetByComponent()</a>
                                </li>
                                <li><a href="Crafty-keyboardDispatch.html">Crafty.keyboardDispatch()</a></li>
                                <li><a href="Crafty-keydown.html">Crafty.keydown</a></li>
                                <li><a href="Crafty-keys.html">Crafty.keys</a></li>
                                <li><a href="Crafty-lastEvent.html">Crafty.lastEvent</a></li>
                                <li><a href="Crafty-mouseButtons.html">Crafty.mouseButtons</a></li>
                                <li><a href="Crafty-mouseDispatch.html">Crafty.mouseDispatch()</a></li>
                                <li><a href="Crafty-mouseWheelDispatch.html">Crafty.mouseWheelDispatch()</a></li>
                                <li><a href="Crafty-multitouch.html">Crafty.multitouch()</a></li>
                                <li><a href="Crafty-selected.html">Crafty.selected</a></li>
                                <li><a href="Crafty-touchDispatch.html">Crafty.touchDispatch()</a></li>
                                <li><a href="Keyboard.html">Keyboard</a></li>
                                <li><a href="Mouse.html">Mouse</a></li>
                                <li><a href="MouseDrag.html">MouseDrag</a></li>
                                <li><a href="Touch.html">Touch</a></li>
                            </ul>
                        </li>
                        <li class="category">杂项
                            <ul class="category-list">
                                <li><a href="Crafty-addEvent.html">Crafty.addEvent()</a></li>
                                <li><a href="Crafty-device.html">Crafty.device</a></li>
                                <li><a href="Crafty-removeEvent.html">Crafty.removeEvent()</a></li>
                                <li><a href="Crafty-support.html">Crafty.support</a></li>
                            </ul>
                        </li>
                        <li class="category">模型
                            <ul class="category-list">
                                <li><a href="Model.html">Model</a></li>
                            </ul>
                        </li>
                        <li class="category">场景
                            <ul class="category-list">
                                <li><a href="Crafty-scene.html">Crafty.scene()</a></li>
                            </ul>
                        </li>
                        <li class="category">舞台<ul class="category-list">
                                <li><a href="Crafty-background.html">Crafty.background()</a></li>
                                <li><a href="Crafty-scene.html">Crafty.scene()</a></li>
                                <li><a href="Crafty-viewport.html">Crafty.viewport</a></li>
                            </ul>
                        </li>
                        <li class="category">工具
                            <ul class="category-list">
                                <li><a href="Crafty-math.html">Crafty.math</a></li>
                                <li><a href="Delay.html">Delay</a></li>
                                <li><a href="Storage.html">Storage</a></li>
                            </ul>
                        </li>
                    </ul>
                </div>
                <div id="doc-content" class="doc-page-holder">
                    <div class="doc-page"><h1>Crafty Core <span></span></h1>
                        <div class="doclet" id="Crafty Core">
                            <div class="triggered-events"><h4>事件</h4>
                                <div class="trigger-list">
                                    <dl class="trigger">
                                        <dt>NewEntityName <span>[<span class="trigger-data"><span class="obj-name">entity name</span><span class="obj-props"> = {String}</span></span>]</span></dt>
                                        <dd>实体设置新名字后</dd>
                                    </dl>
                                    <dl class="trigger">
                                        <dt>NewComponent <span>[<span class="trigger-data"><span class="obj-name">Component</span><span class="obj-props"> = {String}</span></span>]</span></dt>
                                        <dd>实体增加新组件时</dd>
                                    </dl>
                                    <dl class="trigger">
                                        <dt>RemoveComponent <span>[<span class="trigger-data"><span class="obj-name">Component</span><span class="obj-props"> = {String}</span></span>]</span></dt>
                                        <dd>实体移除组件时</dd>
                                    </dl>
                                    <dl class="trigger">
                                        <dt>Remove</dt>
                                        <dd>调用 .destroy() 移除组件时</dd>
                                    </dl>
                                </div>
                            </div>
                            <span class="markdown"><p>每个单独实体增加的一组方法</p>
</span></div>
                        <div><h4>方法</h4>
                            <ul class="page-toc">
                                <li><a href="#-addComponent">.addComponent()</a></li>
                                <li><a href="#-attr">.attr()</a></li>
                                <li><a href="#-bind">.bind()</a></li>
                                <li><a href="#-clone">.clone()</a></li>
                                <li><a href="#-defineField">.defineField()</a></li>
                                <li><a href="#-destroy">.destroy()</a></li>
                                <li><a href="#-each">.each()</a></li>
                                <li><a href="#-get">.get()</a></li>
                                <li><a href="#-getId">.getId()</a></li>
                                <li><a href="#-getName">.getName()</a></li>
                                <li><a href="#-has">.has()</a></li>
                                <li><a href="#-one">.one()</a></li>
                                <li><a href="#-removeComponent">.removeComponent()</a></li>
                                <li><a href="#-requires">.requires()</a></li>
                                <li><a href="#-setName">.setName()</a></li>
                                <li><a href="#-setter">.setter()</a></li>
                                <li><a href="#-timeout">.timeout()</a></li>
                                <li><a href="#-toArray">.toArray()</a></li>
                                <li><a href="#-toggleComponent">.toggleComponent()</a></li>
                                <li><a href="#-trigger">.trigger()</a></li>
                                <li><a href="#-unbind">.unbind()</a></li>
                                <li><a href="#-uniqueBind">.uniqueBind()</a></li>
                            </ul>
                            <div class="doclet" id="-addComponent"><a href="#doc-nav" class="doc-top">回到顶部</a>
                                <h2 class="doclet-header">.addComponent()</h2>
                                <div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">this </span><span class="sig-noun">.addComponent</span></span><span class="sig-seperator">(</span><span class="sig-phrase"><span class="sig-qualifier">String </span><span class="sig-noun">componentList</span></span><span class="sig-seperator">)</span></code>
                                    <dl class="parameter">
                                        <dt> componentList</dt>
                                        <dd><span class="markdown"><p>以逗号 <code>,</code> 隔开的组件字符串</p>
</span></dd>
                                    </dl>
                                </div>
                                <div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">this </span><span class="sig-noun">.addComponent</span></span><span class="sig-seperator">(</span><span class="sig-phrase"><span class="sig-qualifier">String </span><span class="sig-noun">Component1</span></span><span class="sig-seperator">[,</span><span class="sig-phrase"><span class="sig-qualifier"> </span><span class="sig-noun">..</span></span><span class="sig-seperator">,</span><span class="sig-phrase"><span class="sig-qualifier"> </span><span class="sig-qualifier">String </span><span class="sig-noun">ComponentN</span></span><span class="sig-seperator">])</span></code>
                                    <dl class="parameter">
                                        <dt> Component#</dt>
                                        <dd><span class="markdown"><p>新增组件的 ID。</p>
</span></dd>
                                    </dl>
                                </div>
                                <span class="markdown">
                                    <p>为选中实体增加一个组件。</p>
                                    <p>组件用来拓展实体功能。它会复制属性、分配方法来增强实体功能。</p>
                                    <p>你可以通过传递包含所有组件名的字符串（以逗号隔开），或者传递各个组件名作为参数来增加多个组件。</p>
                                    <p>如果组件有 <code>init</code> 方法，方法会被调用</p>
                                    <p>如果实体已经有了该组件，该组件会被忽略（无事发生）。</p>
</span>
                                <div class="example"><h4>示例</h4><span class="markdown"><pre><code class="hljs "><span class="hljs-keyword">this</span>.addComponent(<span class="hljs-string">"2D, Canvas"</span>);
<span class="hljs-keyword">this</span>.addComponent(<span class="hljs-string">"2D"</span>, <span class="hljs-string">"Canvas"</span>);</code></pre></span>
                                </div>
                            </div>
                            <div class="doclet" id="-attr"><a href="#doc-nav" class="doc-top">回到顶部</a>
                                <h2 class="doclet-header">.attr()</h2>
                                <div class="triggered-events"><h4>事件</h4>
                                    <div class="trigger-list">
                                        <dl class="trigger">
                                            <dt>Change <span>[<span class="trigger-data"><span class="obj-name">Data</span><span class="obj-props"> = {key: value}</span></span>]</span></dt>
                                            <dd>属性改变时</dd>
                                        </dl>
                                    </div>
                                </div>
                                <div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">this </span><span class="sig-noun">.attr</span></span><span class="sig-seperator">(</span><span class="sig-phrase"><span class="sig-qualifier">String </span><span class="sig-noun">property</span></span><span class="sig-seperator">,</span><span class="sig-phrase"><span class="sig-qualifier"> </span><span class="sig-qualifier">Any </span><span class="sig-noun">value</span></span><span class="sig-seperator">[,</span><span class="sig-phrase"><span class="sig-qualifier"> </span><span class="sig-qualifier">Boolean </span><span class="sig-noun">silent</span></span><span class="sig-seperator">[,</span><span class="sig-phrase"><span class="sig-qualifier"> </span><span class="sig-qualifier">Boolean </span><span class="sig-noun">recursive</span></span><span class="sig-seperator">]])</span></code>
                                    <dl class="parameter">
                                        <dt> property</dt>
                                        <dd><span class="markdown"><p>实体需要修改的属性</p>
</span></dd>
                                    </dl>
                                    <dl class="parameter">
                                        <dt> value</dt>
                                        <dd><span class="markdown"><p>给属性赋的值</p>
</span></dd>
                                    </dl>
                                    <dl class="parameter">
                                        <dt> silent</dt>
                                        <dd><span class="markdown"><p>如果你想要抑制事件</p>
</span></dd>
                                    </dl>
                                    <dl class="parameter">
                                        <dt> recursive</dt>
                                        <dd><span class="markdown"><p>如果你想要递归地合并</p>
</span></dd>
                                    </dl>
                                </div>
                                <span class="markdown"><p>使用该方法给实体设置任意属性。</p>
</span>
                                <div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">this </span><span class="sig-noun">.attr</span></span><span class="sig-seperator">(</span><span class="sig-phrase"><span class="sig-qualifier">Object </span><span class="sig-noun">map</span></span><span class="sig-seperator">[,</span><span class="sig-phrase"><span class="sig-qualifier"> </span><span class="sig-qualifier">Boolean </span><span class="sig-noun">silent</span></span><span class="sig-seperator">[,</span><span class="sig-phrase"><span class="sig-qualifier"> </span><span class="sig-qualifier">Boolean </span><span class="sig-noun">recursive</span></span><span class="sig-seperator">]])</span></code>
                                    <dl class="parameter">
                                        <dt> map</dt>
                                        <dd><span class="markdown"><p>该对象的键：要修改的属性，值：属性值</p>
</span></dd>
                                    </dl>
                                    <dl class="parameter">
                                        <dt> silent</dt>
                                        <dd><span class="markdown"><p>如果你想要抑制事件</p>
</span></dd>
                                    </dl>
                                    <dl class="parameter">
                                        <dt> recursive</dt>
                                        <dd><span class="markdown"><p>如果你想要递归地合并</p>
</span></dd>
                                    </dl>
                                </div>
                                <span class="markdown">
                                    <p>使用该方法给实体设置多个属性。</p>
                                    <p>设置选项：</p>
                                    <ul>
                                        <li><code>silent</code>：如果你想阻止它启动事件。</li>
                                        <li><code>recursive</code>：如果你传入的对象会覆盖兄弟键，它会递归地合并，而不是简单合并。 默认是 <code>false</code>，除非你使用点号 <code>name.first</code>。</li>
                                    </ul>
                                </span>
                                <div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">Any </span><span class="sig-noun">.attr</span></span><span class="sig-seperator">(</span><span class="sig-phrase"><span class="sig-qualifier">String </span><span class="sig-noun">property</span></span><span class="sig-seperator">)</span></code>
                                    <dl class="parameter">
                                        <dt> property</dt>
                                        <dd><span class="markdown"><p>实体需要修改的属性</p>
</span></dd>
                                    </dl>
                                    <dl class="parameter returns">
                                        <dt class="returns"> [Returns]</dt>
                                        <dd><span class="markdown"><p>值 - 属性的值</p>
</span></dd>
                                    </dl>
                                </div>
                                <span class="markdown"><p>使用该方法获得实体任意属性。你也可以使用 <code>this.property</code> 取得属性值。</p>
</span>
                                <div class="example"><h4>示例</h4><span class="markdown"><pre><code class="hljs "><span class="hljs-keyword">this</span>.attr({<span class="hljs-attr">key</span>: <span class="hljs-string">"value"</span>, <span class="hljs-attr">prop</span>: <span class="hljs-number">5</span>});
<span class="hljs-keyword">this</span>.attr(<span class="hljs-string">"key"</span>); <span class="hljs-comment">// 返回 "value"</span>
<span class="hljs-keyword">this</span>.attr(<span class="hljs-string">"prop"</span>); <span class="hljs-comment">// 返回 5</span>
<span class="hljs-keyword">this</span>.key; <span class="hljs-comment">// "value"</span>
<span class="hljs-keyword">this</span>.prop; <span class="hljs-comment">// 5</span>

<span class="hljs-keyword">this</span>.attr(<span class="hljs-string">"key"</span>, <span class="hljs-string">"newvalue"</span>);
<span class="hljs-keyword">this</span>.attr(<span class="hljs-string">"key"</span>); <span class="hljs-comment">// 返回 "newvalue"</span>
<span class="hljs-keyword">this</span>.key; <span class="hljs-comment">// "newvalue"</span>

<span class="hljs-keyword">this</span>.attr(<span class="hljs-string">"parent.child"</span>, <span class="hljs-string">"newvalue"</span>);
<span class="hljs-keyword">this</span>.parent; <span class="hljs-comment">// {child: "newvalue"};</span>
<span class="hljs-keyword">this</span>.attr(<span class="hljs-string">'parent.child'</span>); <span class="hljs-comment">// "newvalue"</span></code></pre></span></div>
                            </div>
                            <div class="doclet" id="-bind"><a href="#doc-nav" class="doc-top">回到顶部</a>
                                <h2 class="doclet-header">.bind()</h2>
                                <div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">this </span><span class="sig-noun">.bind</span></span><span class="sig-seperator">(</span><span class="sig-phrase"><span class="sig-qualifier">String </span><span class="sig-noun">eventName</span></span><span class="sig-seperator">,</span><span class="sig-phrase"><span class="sig-qualifier"> </span><span class="sig-qualifier">Function </span><span class="sig-noun">callback</span></span><span class="sig-seperator">)</span></code>
                                    <dl class="parameter">
                                        <dt> eventName</dt>
                                        <dd><span class="markdown"><p>要绑定的事件名</p>
</span></dd>
                                    </dl>
                                    <dl class="parameter">
                                        <dt> callback</dt>
                                        <dd><span class="markdown"><p>事件触发后要执行的方法</p>
</span></dd>
                                    </dl>
                                </div>
                                <span class="markdown">
                                    <p>附加当前实体来监听事件。</p>
                                    <p>传递的事件触发后会调用回调函数。根据事件的不同，一些数据可以通过参数传递给回调函数。</p>
                                    <p>第一个参数是事件名（可能是任意值），同时第二个参数是一个回调函数。如果事件有数据，回调函数应该有一个参数。</p>
                                    <p>事件是任意的，并提供组件之间的通信。即使它不存在，也可以触发或绑定事件。</p>
                                    <p>与 DOM 事件不同，Crafty 事件是同步执行的。</p>
                                </span>
                                <div class="example"><h4>示例</h4><span class="markdown"><pre><code class="hljs "><span class="hljs-keyword">this</span>.attr(<span class="hljs-string">"triggers"</span>, <span class="hljs-number">0</span>); <span class="hljs-comment">//设置一个触发器计数</span>
<span class="hljs-keyword">this</span>.bind(<span class="hljs-string">"myevent"</span>, <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">this</span>.triggers++; <span class="hljs-comment">//每当触发 myevent 时，递增</span>
});
<span class="hljs-keyword">this</span>.bind(<span class="hljs-string">"EnterFrame"</span>, <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">this</span>.trigger(<span class="hljs-string">"myevent"</span>); <span class="hljs-comment">// 每帧触发 myevent</span>
});</code></pre></span></div>
                                <div><h4>另请参阅</h4>
                                    <ul class="see-also-list">
                                        <li><a href="#-trigger">.trigger</a></li>
                                        <li><a href="#-unbind">.unbind</a></li>
                                    </ul>
                                </div>
                            </div>
                            <div class="doclet" id="-clone"><a href="#doc-nav" class="doc-top">回到顶部</a>
                                <h2 class="doclet-header">.clone()</h2>
                                <div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">Entity </span><span class="sig-noun">.clone</span></span><span class="sig-seperator">(</span><span class="sig-phrase"><span class="sig-noun">void</span></span><span class="sig-seperator">)</span></code>
                                    <dl class="parameter returns">
                                        <dt class="returns"> [Returns]</dt>
                                        <dd><span class="markdown"><p>当前实体的克隆</p>
</span></dd>
                                    </dl>
                                </div>
                                <span class="markdown"><p>该方法将创建具有与当前实体相同的属性、组件和方法的另一个实体。</p>
</span></div>
                            <div class="doclet" id="-defineField"><a href="#doc-nav" class="doc-top">回到顶部</a>
                                <h2 class="doclet-header">.defineField()</h2>
                                <div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">this </span><span class="sig-noun">.defineField</span></span><span class="sig-seperator">(</span><span class="sig-phrase"><span class="sig-qualifier">String </span><span class="sig-noun">property</span></span><span class="sig-seperator">,</span><span class="sig-phrase"><span class="sig-qualifier"> </span><span class="sig-qualifier">Function </span><span class="sig-noun">getCallback</span></span><span class="sig-seperator">,</span><span class="sig-phrase"><span class="sig-qualifier"> </span><span class="sig-qualifier">Function </span><span class="sig-noun">setCallback</span></span><span class="sig-seperator">)</span></code>
                                    <dl class="parameter">
                                        <dt> property</dt>
                                        <dd><span class="markdown"><p>要分配 getter 和 setter 的属性名</p>
</span></dd>
                                    </dl>
                                    <dl class="parameter">
                                        <dt> getCallback</dt>
                                        <dd><span class="markdown"><p>属性被访问执行的方法</p>
</span></dd>
                                    </dl>
                                    <dl class="parameter">
                                        <dt> setCallback</dt>
                                        <dd><span class="markdown"><p>属性被改变执行的方法</p>
</span></dd>
                                    </dl>
                                </div>
                                <span class="markdown"><p>分配 getter 和 setter 给属性。getter 将监视等待访问的属性，然后在尝试检索时调用给定的取值回调函数。setter 将监视等待改变的属性，然后在尝试修改时调用给定的赋值回调函数。</p>
</span>
                                <div class="example"><h4>示例</h4><span class="markdown"><pre><code class="hljs "><span class="hljs-keyword">var</span> ent = Crafty.e(<span class="hljs-string">"2D"</span>);
ent.defineField(<span class="hljs-string">"customData"</span>, <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{
   <span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span>._customData;
}, <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">newValue</span>) </span>{
   <span class="hljs-keyword">this</span>._customData = newValue;
});

ent.customData = <span class="hljs-string">"2"</span> <span class="hljs-comment">// 设置 customData 为 2</span>
Crafty.log(ent.customData) <span class="hljs-comment">// 打印 2</span></code></pre></span></div>
                            </div>
                            <div class="doclet" id="-destroy"><a href="#doc-nav" class="doc-top">回到顶部</a>
                                <h2 class="doclet-header">.destroy()</h2>
                                <div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">this </span><span class="sig-noun">.destroy</span></span><span class="sig-seperator">(</span><span class="sig-phrase"><span class="sig-noun">void</span></span><span class="sig-seperator">)</span></code></div>
                                <span class="markdown"><p>移除所有事件监听器，删除所有属性，并从关卡移除</p>
</span></div>
                            <div class="doclet" id="-each"><a href="#doc-nav" class="doc-top">回到顶部</a>
                                <h2 class="doclet-header">.each()</h2>
                                <div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">this </span><span class="sig-noun">.each</span></span><span class="sig-seperator">(</span><span class="sig-phrase"><span class="sig-qualifier">Function </span><span class="sig-noun">method</span></span><span class="sig-seperator">)</span></code>
                                    <dl class="parameter">
                                        <dt> method</dt>
                                        <dd><span class="markdown">
                                            <p>每次迭代调用的方法</p>
                                        </span></dd>
                                    </dl>
                                </div>
                                <span class="markdown">
                                    <p>迭代发现的实体，为每个实体调用函数。</p>
                                    <p>为每个实体调用这个方法，并且把迭代的索引作为参数传递。方法的上下文（<code>this</code> 的值）是迭代中的当前实体。</p>
                                </span>
                                <div class="example"><h4>示例</h4><span class="markdown"><p>销毁次序为偶数的 2D 实体</p>
<pre><code class="hljs ">Crafty(<span class="hljs-string">"2D"</span>).each(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">i</span>) </span>{
    <span class="hljs-keyword">if</span>(i % <span class="hljs-number">2</span> === <span class="hljs-number">0</span>) {
        <span class="hljs-keyword">this</span>.destroy();
    }
});</code></pre></span></div>
                            </div>
                            <div class="doclet" id="-get"><a href="#doc-nav" class="doc-top">回到顶部</a>
                                <h2 class="doclet-header">.get()</h2>
                                <div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">Array </span><span class="sig-noun">.get</span></span><span class="sig-seperator">()</span></code>
                                    <dl class="parameter returns">
                                        <dt class="returns"> [Returns]</dt>
                                        <dd><span class="markdown"><p>与活动选择器相对应的一组实体</p>
</span></dd>
                                    </dl>
                                </div>
                                <div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">Entity </span><span class="sig-noun">.get</span></span><span class="sig-seperator">(</span><span class="sig-phrase"><span class="sig-qualifier">Number </span><span class="sig-noun">index</span></span><span class="sig-seperator">)</span></code>
                                    <dl class="parameter returns">
                                        <dt class="returns"> [Returns]</dt>
                                        <dd><span class="markdown"><p>属于当前选择的实体</p>
</span></dd>
                                    </dl>
                                    <dl class="parameter">
                                        <dt> index</dt>
                                        <dd><span class="markdown"><p>将要返回的实体的索引。如果为负，从数组末尾计数。</p>
</span></dd>
                                    </dl>
                                </div>
                                <div class="example"><h4>示例</h4><span class="markdown"><p>获取包含所有“2D”实体的数组</p>
<pre><code class="hljs "><span class="hljs-keyword">var</span> arr = Crafty(<span class="hljs-string">"2D"</span>).get()</code></pre><p>获取第一个匹配选择器的实体</p>
<pre><code class="hljs "><span class="hljs-comment">// 等同于 Crafty("2D").get()[0]，但是不能创建新数组</span>
<span class="hljs-keyword">var</span> e = Crafty(<span class="hljs-string">"2D"</span>).get(<span class="hljs-number">0</span>)</code></pre><p>获取匹配选择器的最后一个“2D”实体</p>
<pre><code class="hljs "><span class="hljs-keyword">var</span> e = Crafty(<span class="hljs-string">"2D"</span>).get(<span class="hljs-number">-1</span>)</code></pre></span></div>
                            </div>
                            <div class="doclet" id="-getId"><a href="#doc-nav" class="doc-top">回到顶部</a>
                                <h2 class="doclet-header">.getId()</h2>
                                <div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">Number </span><span class="sig-noun">.getId</span></span><span class="sig-seperator">(</span><span class="sig-phrase"><span class="sig-noun">void</span></span><span class="sig-seperator">)</span></code>
                                    <dl class="parameter returns">
                                        <dt class="returns"> [Returns]</dt>
                                        <dd><span class="markdown"><p>实体 ID</p>
</span></dd>
                                    </dl>
                                </div>
                                <span class="markdown"><p>为了更好的性能，简单地使用 this[0] 属性。</p>
</span>
                                <div class="example"><h4>示例</h4><span class="markdown"><p>返回属性 <code>0</code> 可以找出实体 <code>ID</code>。</p>
<pre><code class="hljs ">   <span class="hljs-keyword">var</span> ent = Crafty.e(<span class="hljs-string">"2D"</span>);
   ent[<span class="hljs-number">0</span>]; <span class="hljs-comment">//ID</span>
   ent.getId(); <span class="hljs-comment">//也是 ID</span></code></pre></span></div>
                            </div>
                            <div class="doclet" id="-getName"><a href="#doc-nav" class="doc-top">回到顶部</a>
                                <h2 class="doclet-header">.getName()</h2>
                                <div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">this </span><span class="sig-noun">.getName</span></span><span class="sig-seperator">(</span><span class="sig-phrase"><span class="sig-qualifier">String </span><span class="sig-noun">name</span></span><span class="sig-seperator">)</span></code>
                                    <dl class="parameter returns">
                                        <dt class="returns"> [Returns]</dt>
                                        <dd><span class="markdown"><p>用于调试目的的对人友好的名称。</p>
</span></dd>
                                    </dl>
                                </div>
                                <span class="markdown"><p>获取用于调试目的的易读名称。</p>
</span>
                                <div class="example"><h4>示例</h4><span class="markdown"><pre><code class="hljs "><span class="hljs-keyword">var</span> ent = Crafty.e().setName(<span class="hljs-string">"Player"</span>);
<span class="hljs-keyword">var</span> name = ent.getName();</code></pre></span></div>
                                <div><h4>另请参阅</h4>
                                    <ul class="see-also-list">
                                        <li><a href="Crafty Core.html#-setName">Crafty Core.setName</a></li>
                                    </ul>
                                </div>
                            </div>
                            <div class="doclet" id="-has"><a href="#doc-nav" class="doc-top">回到顶部</a>
                                <h2 class="doclet-header">.has()</h2>
                                <div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">Boolean </span><span class="sig-noun">.has</span></span><span class="sig-seperator">(</span><span class="sig-phrase"><span class="sig-qualifier">String </span><span class="sig-noun">component</span></span><span class="sig-seperator">)</span></code>
                                    <dl class="parameter">
                                        <dt> component</dt>
                                        <dd><span class="markdown"><p>要检查的组件的名称</p>
</span></dd>
                                    </dl>
                                    <dl class="parameter returns">
                                        <dt class="returns"> [Returns]</dt>
                                        <dd><span class="markdown"><p><code>true</code> 或 <code>false</code> 取决于实体是否有给定组件。</p>
</span></dd>
                                    </dl>
                                </div>
                                <span class="markdown">
                                    <p>为了更好的性能，简单地使用 <code>.__c</code> 对象，如果实体有给定组件，该对象为 <code>true</code> ，否则，该对象不存在（或者是 <code>false</code>）。</p>
                                </span>
                            </div>
                            <div class="doclet" id="-one"><a href="#doc-nav" class="doc-top">回到顶部</a>
                                <h2 class="doclet-header">.one()</h2>
                                <div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">Number </span><span class="sig-noun">one</span></span><span class="sig-seperator">(</span><span class="sig-phrase"><span class="sig-qualifier">String </span><span class="sig-noun">eventName</span></span><span class="sig-seperator">,</span><span class="sig-phrase"><span class="sig-qualifier"> </span><span class="sig-qualifier">Function </span><span class="sig-noun">callback</span></span><span class="sig-seperator">)</span></code>
                                    <dl class="parameter">
                                        <dt> eventName</dt>
                                        <dd><span class="markdown"><p>要绑定的事件名称</p>
</span></dd>
                                    </dl>
                                    <dl class="parameter">
                                        <dt> callback</dt>
                                        <dd><span class="markdown"><p>事件出发时执行的函数</p>
</span></dd>
                                    </dl>
                                    <dl class="parameter returns">
                                        <dt class="returns"> [Returns]</dt>
                                        <dd><span class="markdown"><p>用来解绑的当前回调函数的 ID</p>
</span></dd>
                                    </dl>
                                </div>
                                <span class="markdown"><p>作用类似 Crafty.bind，但是事件触发后就会解绑。</p>
</span>
                                <div><h4>另请参阅</h4>
                                    <ul class="see-also-list">
                                        <li><a href="#-bind">.bind</a></li>
                                    </ul>
                                </div>
                            </div>
                            <div class="doclet" id="-removeComponent"><a href="#doc-nav" class="doc-top">回到顶部</a>
                                <h2 class="doclet-header">.removeComponent()</h2>
                                <div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">this </span><span class="sig-noun">.removeComponent</span></span><span class="sig-seperator">(</span><span class="sig-phrase"><span class="sig-qualifier">String </span><span class="sig-noun">Component</span></span><span class="sig-seperator">[,</span><span class="sig-phrase"><span class="sig-qualifier"> </span><span class="sig-noun">soft</span></span><span class="sig-seperator">])</span></code>
                                    <dl class="parameter">
                                        <dt> component</dt>
                                        <dd><span class="markdown"><p>要移除的组件</p>
</span></dd>
                                    </dl>
                                    <dl class="parameter">
                                        <dt> soft</dt>
                                        <dd><span class="markdown"><p>是否软移除（默认 <code>true</code>）</p>
</span></dd>
                                    </dl>
                                </div>
                                <span class="markdown">
                                    <p>从实体移除一个组件。软移除（默认）只能避免 <code>.has()</code> 返回 true。硬移除会移除所有关联属性和方法。</p>
</span>
                                <div class="example"><h4>示例</h4><span class="markdown"><pre><code class="hljs "><span class="hljs-keyword">var</span> e = Crafty.e(<span class="hljs-string">"2D,DOM,Test"</span>);
e.removeComponent(<span class="hljs-string">"Test"</span>);        <span class="hljs-comment">//软移除 Test 组件</span>
e.removeComponent(<span class="hljs-string">"Test"</span>, <span class="hljs-literal">false</span>); <span class="hljs-comment">//硬移除 Test 组件</span></code></pre></span>
                                </div>
                            </div>
                            <div class="doclet" id="-requires"><a href="#doc-nav" class="doc-top">回到顶部</a>
                                <h2 class="doclet-header">.requires()</h2>
                                <div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">this </span><span class="sig-noun">.requires</span></span><span class="sig-seperator">(</span><span class="sig-phrase"><span class="sig-qualifier">String </span><span class="sig-noun">componentList</span></span><span class="sig-seperator">)</span></code>
                                    <dl class="parameter">
                                        <dt> componentList</dt>
                                        <dd><span class="markdown"><p>必须添加的组件列表</p>
</span></dd>
                                    </dl>
                                </div>
                                <span class="markdown">
                                    <p>确保实体有列出的组件。如果没有，新增组件。</p>
                                    <p>（当天 Crafty 版本中，该方法的行为与 <code>addComponent</code> 完全相同。根据惯例，开发者使用 <code>requires</code> 进行组件依赖 —— 例如：具体地指出，只有当另一个组件存在时，一个组件才能正常工作 —— 在其他所有情况下使用 <code>requires</code>。）</p>
</span>
                                <div><h4>另请参阅</h4>
                                    <ul class="see-also-list">
                                        <li><a href="#-addComponent">.addComponent</a></li>
                                    </ul>
                                </div>
                            </div>
                            <div class="doclet" id="-setName"><a href="#doc-nav" class="doc-top">回到顶部</a>
                                <h2 class="doclet-header">.setName()</h2>
                                <div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">this </span><span class="sig-noun">.setName</span></span><span class="sig-seperator">(</span><span class="sig-phrase"><span class="sig-qualifier">String </span><span class="sig-noun">name</span></span><span class="sig-seperator">)</span></code>
                                    <dl class="parameter">
                                        <dt> name</dt>
                                        <dd><span class="markdown"><p>出于调试目的的对人友好的容易理解的名字。</p>
</span></dd>
                                    </dl>
                                </div>
                                <span class="markdown"><p>设置出于调试目的的对人友好的容易理解的名字。</p>
</span>
                                <div class="example"><h4>示例</h4><span class="markdown"><pre><code class="hljs "><span class="hljs-keyword">var</span> ent = Crafty.e().setName(<span class="hljs-string">"Player"</span>);</code></pre></span></div>
                                <div><h4>另请参阅</h4>
                                    <ul class="see-also-list">
                                        <li><a href="Crafty Core.html#-getName">Crafty Core.getName</a></li>
                                    </ul>
                                </div>
                            </div>
                            <div class="doclet" id="-setter"><a href="#doc-nav" class="doc-top">回到顶部</a>
                                <h2 class="doclet-header">.setter()</h2>
                                <div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">this </span><span class="sig-noun">.setter</span></span><span class="sig-seperator">(</span><span class="sig-phrase"><span class="sig-qualifier">String </span><span class="sig-noun">property</span></span><span class="sig-seperator">,</span><span class="sig-phrase"><span class="sig-qualifier"> </span><span class="sig-qualifier">Function </span><span class="sig-noun">callback</span></span><span class="sig-seperator">)</span></code>
                                    <dl class="parameter">
                                        <dt> property</dt>
                                        <dd><span class="markdown"><p>被监视是否被修改的属性</p>
</span></dd>
                                    </dl>
                                    <dl class="parameter">
                                        <dt> callback</dt>
                                        <dd><span class="markdown"><p>属性被修改后的回调函数</p>
</span></dd>
                                    </dl>
                                </div>
                                <span class="markdown"><p>将监视等待修改的属性，然后在尝试修改时调用给定的回调函数。</p>
                                    <p>不建议使用这个功能；使用 .defineField() </p>
                                </span>
                                <div><h4>另请参阅</h4>
                                    <ul class="see-also-list">
                                        <li><a href="#-defineField">.defineField</a></li>
                                    </ul>
                                </div>
                            </div>
                            <div class="doclet" id="-timeout"><a href="#doc-nav" class="doc-top">回到顶部</a>
                                <h2 class="doclet-header">.timeout()</h2>
                                <div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">this </span><span class="sig-noun">.timeout</span></span><span class="sig-seperator">(</span><span class="sig-phrase"><span class="sig-qualifier">Function </span><span class="sig-noun">callback</span></span><span class="sig-seperator">,</span><span class="sig-phrase"><span class="sig-qualifier"> </span><span class="sig-qualifier">Number </span><span class="sig-noun">delay</span></span><span class="sig-seperator">)</span></code>
                                    <dl class="parameter">
                                        <dt> callback</dt>
                                        <dd><span class="markdown"><p>在给定毫秒数后执行的函数</p>
</span></dd>
                                    </dl>
                                    <dl class="parameter">
                                        <dt> delay</dt>
                                        <dd><span class="markdown"><p>延迟执行函数的毫秒数</p>
</span></dd>
                                    </dl>
                                </div>
                                <span class="markdown">
                                    <p>延迟方法将在给定的毫秒数后执行一个函数。</p>
                                    <p>本质上是 <code>setTimeout</code> 的包装器。</p>
                                </span>
                                <div class="example"><h4>示例</h4><span class="markdown"><p>100 毫秒后销毁自身</p>
<pre><code class="hljs "><span class="hljs-keyword">this</span>.timeout(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{
<span class="hljs-keyword">this</span>.destroy();
}, <span class="hljs-number">100</span>);</code></pre></span></div>
                            </div>
                            <div class="doclet" id="-toArray"><a href="#doc-nav" class="doc-top">回到顶部</a>
                                <h2 class="doclet-header">.toArray()</h2>
                                <div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">this </span><span class="sig-noun">.toArray</span></span><span class="sig-seperator">(</span><span class="sig-phrase"><span class="sig-noun">void</span></span><span class="sig-seperator">)</span></code></div>
                                <span class="markdown"><p>该方法将简单地将发现的实体返回为一个 id 数组。要获得真实实体列表，使用 <code>get()</code>。</p>
</span>
                                <div><h4>另请参阅</h4>
                                    <ul class="see-also-list">
                                        <li><a href="#-get">.get</a></li>
                                    </ul>
                                </div>
                            </div>
                            <div class="doclet" id="-toggleComponent"><a href="#doc-nav" class="doc-top">回到顶部</a>
                                <h2 class="doclet-header">.toggleComponent()</h2>
                                <div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">this </span><span class="sig-noun">.toggleComponent</span></span><span class="sig-seperator">(</span><span class="sig-phrase"><span class="sig-qualifier">String </span><span class="sig-noun">ComponentList</span></span><span class="sig-seperator">)</span></code>
                                    <dl class="parameter">
                                        <dt> ComponentList</dt>
                                        <dd><span class="markdown"><p>以逗号 <code>,</code> 隔开的将要添加或删除的组件字符串</p>
</span></dd>
                                    </dl>
                                </div>
                                <div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">this </span><span class="sig-noun">.toggleComponent</span></span><span class="sig-seperator">(</span><span class="sig-phrase"><span class="sig-qualifier">String </span><span class="sig-noun">Component1</span></span><span class="sig-seperator">[,</span><span class="sig-phrase"><span class="sig-qualifier"> </span><span class="sig-noun">..</span></span><span class="sig-seperator">,</span><span class="sig-phrase"><span class="sig-qualifier"> </span><span class="sig-qualifier">String </span><span class="sig-noun">componentN</span></span><span class="sig-seperator">])</span></code>
                                    <dl class="parameter">
                                        <dt> Component#</dt>
                                        <dd><span class="markdown"><p>将要添加或删除的组件 ID。</p>
</span></dd>
                                    </dl>
                                </div>
                                <span class="markdown"><p>Add or Remove Components from an entity.</p>
</span>
                                <div class="example"><h4>示例</h4><span class="markdown"><pre><code class="hljs "><span class="hljs-keyword">var</span> e = Crafty.e(<span class="hljs-string">"2D,DOM,Test"</span>);
e.toggleComponent(<span class="hljs-string">"Test,Test2"</span>); <span class="hljs-comment">//Remove Test, add Test2</span>
e.toggleComponent(<span class="hljs-string">"Test,Test2"</span>); <span class="hljs-comment">//Add Test, remove Test2</span></code></pre><pre><code class="hljs "><span class="hljs-keyword">var</span> e = Crafty.e(<span class="hljs-string">"2D,DOM,Test"</span>);
e.toggleComponent(<span class="hljs-string">"Test"</span>,<span class="hljs-string">"Test2"</span>); <span class="hljs-comment">//Remove Test, add Test2</span>
e.toggleComponent(<span class="hljs-string">"Test"</span>,<span class="hljs-string">"Test2"</span>); <span class="hljs-comment">//Add Test, remove Test2</span>
e.toggleComponent(<span class="hljs-string">"Test"</span>);         <span class="hljs-comment">//Remove Test</span></code></pre></span></div>
                            </div>
                            <div class="doclet" id="-trigger"><a href="#doc-nav" class="doc-top">回到顶部</a>
                                <h2 class="doclet-header">.trigger()</h2>
                                <div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">this </span><span class="sig-noun">.trigger</span></span><span class="sig-seperator">(</span><span class="sig-phrase"><span class="sig-qualifier">String </span><span class="sig-noun">eventName</span></span><span class="sig-seperator">[,</span><span class="sig-phrase"><span class="sig-qualifier"> </span><span class="sig-qualifier">Object </span><span class="sig-noun">data</span></span><span class="sig-seperator">])</span></code>
                                    <dl class="parameter">
                                        <dt> eventName</dt>
                                        <dd><span class="markdown"><p>要触发的事件</p>
</span></dd>
                                    </dl>
                                    <dl class="parameter">
                                        <dt> data</dt>
                                        <dd><span class="markdown"><p>将被作为参数传入每个回调函数的任意数据</p>
</span></dd>
                                    </dl>
                                </div>
                                <span class="markdown">
                                    <p>触发携带任意数据的事件。将会调用所有带有当前实体对象的上下文（<code>this</code> 的值）的回调函数。</p>
                                    <p><em>注意：这只会在当前实体内执行回调函数，没有其他实体。</em></p>
                                    <p>第一个参数是要出发的事件的名字，可选参数是任意事件数据。这可以是任何东西。</p>
                                    <p>与 DOM 事件不同，Crafty 事件是同步执行的。</p>
                                </span>
                            </div>
                            <div class="doclet" id="-unbind"><a href="#doc-nav" class="doc-top">回到顶部</a>
                                <h2 class="doclet-header">.unbind()</h2>
                                <div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">this </span><span class="sig-noun">.unbind</span></span><span class="sig-seperator">(</span><span class="sig-phrase"><span class="sig-qualifier">String </span><span class="sig-noun">eventName</span></span><span class="sig-seperator">[,</span><span class="sig-phrase"><span class="sig-qualifier"> </span><span class="sig-qualifier">Function </span><span class="sig-noun">callback</span></span><span class="sig-seperator">])</span></code>
                                    <dl class="parameter">
                                        <dt> eventName</dt>
                                        <dd><span class="markdown"><p>要解绑的事件的名称</p>
</span></dd>
                                    </dl>
                                    <dl class="parameter">
                                        <dt> callback</dt>
                                        <dd><span class="markdown"><p>要解绑的回调函数</p>
</span></dd>
                                    </dl>
                                </div>
                                <span class="markdown">
                                    <p>从当前实体移除绑定的事件。</p>
                                    <p>传递一个事件名称，将移除所有与该事件绑定的事件。传递回调函数的引用只会解绑该回调函数。</p>
                                </span>
                                <div><h4>另请参阅</h4>
                                    <ul class="see-also-list">
                                        <li><a href="#-bind">.bind</a></li>
                                        <li><a href="#-trigger">.trigger</a></li>
                                    </ul>
                                </div>
                            </div>
                            <div class="doclet" id="-uniqueBind"><a href="#doc-nav" class="doc-top">回到顶部</a>
                                <h2 class="doclet-header">.uniqueBind()</h2>
                                <div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">Number </span><span class="sig-noun">.uniqueBind</span></span><span class="sig-seperator">(</span><span class="sig-phrase"><span class="sig-qualifier">String </span><span class="sig-noun">eventName</span></span><span class="sig-seperator">,</span><span class="sig-phrase"><span class="sig-qualifier"> </span><span class="sig-qualifier">Function </span><span class="sig-noun">callback</span></span><span class="sig-seperator">)</span></code>
                                    <dl class="parameter">
                                        <dt> eventName</dt>
                                        <dd><span class="markdown"><p>要绑定到的事件的名称</p>
</span></dd>
                                    </dl>
                                    <dl class="parameter">
                                        <dt> callback</dt>
                                        <dd><span class="markdown"><p>事件触发时执行的函数</p>
</span></dd>
                                    </dl>
                                    <dl class="parameter returns">
                                        <dt class="returns"> [Returns]</dt>
                                        <dd><span class="markdown"><p>用来解绑的当前回调函数 ID</p>
</span></dd>
                                    </dl>
                                </div>
                                <span class="markdown"><p>作用类似 Crafty.bind，但是防止回调函数多次绑定。</p>
</span>
                                <div><h4>另请参阅</h4>
                                    <ul class="see-also-list">
                                        <li><a href="#-bind">.bind</a></li>
                                    </ul>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

        </div>
    </div>
    <div class="clearer"></div>
    <div id="footer">
        <div id="contact">
            <a href="https://groups.google.com/forum/#!forum/craftyjs">
                <img src="../images/google.png">
                google groups</a>
            <a href="mailto:starwed@gmail.com">
                <img src="../images/email.png">
                starwed@gmail.com</a>
            <a href="https://github.com/craftyjs/Crafty">
                <img src="../images/github.png">
                github</a>
        </div>
        <ul>
            <li><a href="../">首页</a></li>
            <li><a href="../getting-started/">快速开始</a></li>
            <li><a href="../documentation/">文档</a></li>
            <li><a href="../api/">API</a></li>
            <li><a href="../components/">组件</a></li>
            <li class="emph"><a href="../#install">下载</a></li>
        </ul>
        <p>
            © Crafty 2010-2015. Crafty is distributed under the <a href="http://en.wikipedia.org/wiki/MIT_License">MIT
            License</a>.
        </p>
    </div>
</div>


</body></html>